added option to use a suffix for singular forms - #28
Open
Simone-RM wants to merge 1 commit into
Open
Conversation
williamhjcho
requested changes
Feb 13, 2026
williamhjcho
left a comment
Owner
There was a problem hiding this comment.
Thank you for the PR!
Please take a look at the comments, and if possible, please also add some tests for both the I18NextOptions and for this new behavior
| nestingPrefix: r'$t(', | ||
| nestingSuffix: ')', | ||
| nestingSeparator: ',', | ||
| singularSuffix: 'singular', |
Owner
There was a problem hiding this comment.
to avoid breaking localization changes, the default should still be maintained
Comment on lines
+145
to
+152
| /// Defaults to 'singular' and is used for simple pluralization rules. | ||
| /// | ||
| /// For example, in english where it only has singular or plural forms: | ||
| /// | ||
| /// ``` | ||
| /// "friend_singular": "A friend" | ||
| /// "friend_plural": "{{count}} friends" | ||
| /// ``` |
Owner
There was a problem hiding this comment.
here too, the default should be null to maintain the existing behavior
Comment on lines
-148
to
+162
| /// "friend": "A friend" | ||
| /// "friend_singular": "A friend" |
Owner
There was a problem hiding this comment.
✂️ keep default behavior docs
Comment on lines
-17
to
+25
| final suffix = options.pluralSuffix ?? 'plural'; | ||
| return index == 0 ? '' : '$separator$suffix'; | ||
| late final String suffix; | ||
|
|
||
| if (index == 0) { | ||
| suffix = options.singularSuffix ?? 'singular'; | ||
| } else { | ||
| suffix = options.pluralSuffix ?? 'plural'; | ||
| } | ||
|
|
||
| return suffix.isEmpty ? '' : '$separator$suffix'; |
Owner
There was a problem hiding this comment.
since the base options are merged, we could do the following here to simplify this expression:
- the singular and plural suffixes from options could just be the values themselves (from option), and remove the fallbacks from this function as to rely only on options directly.
- then the return should check if the suffix actually exists, or if it should be ignored
this is what I mean:
final suffix = index == 0 ? options.singularSuffix : options.pluralSuffix;
return suffix == null || suffix.isEmpty ? '' : '$separator$suffix';
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Having only "key" and "key_plural" breaks some translation tools which expect "key" to have no variants and only support plural forms if they all have a suffix